#!/bin/zsh  # MacOS 环境
#!/usr/bin/env sh  # Windows 环境

# 使用该脚本时将对应环境标识移动到第一行

# 确保脚本抛出遇到的错误
set -e

# 生成静态文件
echo "==>😈  Generating static files..."
npm run docs:build

# 进入生成的文件夹
echo "==>😈  Entering build directory..."
cd docs/.vitepress/dist

# 初始化 Git 仓库
echo "==>😈  Initializing Git repository..."
git init

# 添加所有文件到 Git 仓库
echo "==>😈  Adding all files to Git..."
git add -A

# 获取当前北京时间并格式化
echo "==>😈  Get the current Beijing time and format it..."
CURRENT_TIME=$(TZ='Asia/Shanghai' date +'%Y-%m-%d %H:%M:%S')

# 提交更改，包含当前北京时间
echo "==>😈  Committing changes with current Beijing time: $CURRENT_TIME..."
git commit -m "deploy at $CURRENT_TIME"

# 推送到 GitHub
echo "==>😈 Pushing to GitHub..."
git push -f https://github.com/IndulgeBack/IndulgeBack.git main:blog-pages

# 返回原始目录
echo "==>😈  Returning to original directory..."
echo "==>😈  🏅当前版本部署完成，版本部署于北京时间: $CURRENT_TIME...🏅"
cd -